<ix-modal-header
  [requiredRoles]="requiredRoles"
  [title]="title"
  [loading]="isLoading()"
></ix-modal-header>

<mat-card>
  <mat-card-content>
    <form class="ix-form-container" [formGroup]="form" (submit)="submit()">
      <ix-fieldset [title]="'Basic' | translate">
        <ix-explorer
          formControlName="path"
          [required]="true"
          [tooltip]="helptextSharingSmb.pathTooltip | translate"
          [label]="helptextSharingSmb.pathLabel | translate"
          [nodeProvider]="treeNodeProvider"
          [canCreateDataset]="isNew"
          [createDatasetProps]="createDatasetProps"
          [rootNodes]="rootNodes()"
        ></ix-explorer>

        <ix-input
          formControlName="name"
          [label]="helptextSharingSmb.nameLabel | translate"
          [required]="true"
        ></ix-input>

        <ix-select
          formControlName="purpose"
          emptyValue=""
          [label]="helptextSharingSmb.purposeLabel | translate"
          [tooltip]="helptextSharingSmb.purposeTooltip | translate"
          [required]="true"
          [options]="purposeOptions$"
        ></ix-select>

        <ix-input
          formControlName="comment"
          [label]="helptextSharingSmb.commentLabel | translate"
        ></ix-input>

        <ix-checkbox
          formControlName="enabled"
          [label]="helptextSharingSmb.enabledLabel | translate"
        ></ix-checkbox>
      </ix-fieldset>

      @if (isAdvancedMode) {
        <ix-fieldset [title]="'Access' | translate">
          <ix-checkbox
            formControlName="acl"
            [label]="helptextSharingSmb.aclLabel | translate"
            [tooltip]="helptextSharingSmb.aclTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="ro"
            [label]="helptextSharingSmb.readOnlyLabel | translate"
            [tooltip]="helptextSharingSmb.readOnlyTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="browsable"
            [label]="helptextSharingSmb.browsableLabel | translate"
            [tooltip]="helptextSharingSmb.browsableTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="guestok"
            [label]="helptextSharingSmb.guestokLabel | translate"
            [tooltip]="helptextSharingSmb.guestokTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="abe"
            [label]="helptextSharingSmb.abeLabel | translate"
            [tooltip]="helptextSharingSmb.abeTooltip | translate"
          ></ix-checkbox>

          <ix-chips
            formControlName="hostsallow"
            [label]="helptextSharingSmb.hostsallowLabel | translate"
            [tooltip]="hostsAllowTooltip"
          ></ix-chips>

          <ix-chips
            formControlName="hostsdeny"
            [label]="helptextSharingSmb.hostsdenyLabel | translate"
            [tooltip]="helptextSharingSmb.hostsdenyTooltip | translate"
          ></ix-chips>
        </ix-fieldset>

        <ix-fieldset formGroupName="audit" [title]="'Audit Logging' | translate">
          <ix-checkbox
            formControlName="enable"
            [label]="helptextSharingSmb.enabledLabel | translate"
            [tooltip]="helptextSharingSmb.auditLogTooltip | translate"
          ></ix-checkbox>

          <ix-chips
            formControlName="watch_list"
            [hint]="'Keep this list empty to Watch All' | translate"
            [label]="'Watch List' | translate"
            [tooltip]="helptextSharingSmb.watchListTooltip | translate"
            [autocompleteProvider]="groupProvider"
            [allowNewEntries]="false"
          ></ix-chips>

          <ix-chips
            formControlName="ignore_list"
            [label]="'Ignore List' | translate"
            [tooltip]="helptextSharingSmb.ignoreListTooltip | translate"
            [autocompleteProvider]="groupProvider"
            [allowNewEntries]="false"
          ></ix-chips>
        </ix-fieldset>

        <ix-fieldset [title]="'Other Options' | translate">
          <ix-checkbox
            formControlName="home"
            [label]="helptextSharingSmb.homeLabel | translate"
            [tooltip]="helptextSharingSmb.homeTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="timemachine"
            [label]="helptextSharingSmb.timemachineLabel | translate"
            [tooltip]="helptextSharingSmb.timemachineTooltip | translate"
          ></ix-checkbox>

          <div [hidden]="!form.value.timemachine">
            <ix-input
              formControlName="timemachine_quota"
              [label]="helptextSharingSmb.timemachineQuotaLabel | translate"
              [tooltip]="helptextSharingSmb.timemachineQuotaTooltip | translate"
              [format]="formatter.memorySizeFormatting"
              [parse]="formatter.memorySizeParsing"
            ></ix-input>
          </div>

          <ix-checkbox
            formControlName="afp"
            [label]="helptextSharingSmb.afpLabel | translate"
            [tooltip]="helptextSharingSmb.afpTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="shadowcopy"
            [label]="helptextSharingSmb.shadowcopyLabel | translate"
            [tooltip]="helptextSharingSmb.shadowcopyTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="recyclebin"
            [label]="helptextSharingSmb.recyclebinLabel | translate"
            [tooltip]="helptextSharingSmb.recyclebinTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="aapl_name_mangling"
            [label]="helptextSharingSmb.aaplNameManglingLabel | translate"
            [tooltip]="helptextSharingSmb.aaplNameManglingTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="streams"
            [label]="helptextSharingSmb.streamsLabel | translate"
            [tooltip]="helptextSharingSmb.streamsTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="durablehandle"
            [label]="helptextSharingSmb.durablehandleLabel | translate"
            [tooltip]="helptextSharingSmb.durablehandleTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="fsrvp"
            [label]="helptextSharingSmb.fsrvpLabel | translate"
            [tooltip]="helptextSharingSmb.fsrvpTooltip | translate"
          ></ix-checkbox>

          <ix-input
            formControlName="path_suffix"
            [label]="helptextSharingSmb.pathSuffixLabel | translate"
            [tooltip]="helptextSharingSmb.pathSuffixTooltip | translate"
          ></ix-input>

          <ix-input
            formControlName="auxsmbconf"
            [label]="helptextSharingSmb.auxsmbconfLabel | translate"
            [tooltip]="helptextSharingSmb.auxsmbconfTooltip | translate"
          ></ix-input>
        </ix-fieldset>
      }

      <ix-form-actions>
        <button
          *ixRequiresRoles="requiredRoles"
          mat-button
          type="submit"
          color="primary"
          ixTest="save"
          [disabled]="form.invalid || isLoading() || isAsyncValidatorPending"
        >
          {{ 'Save' | translate }}
        </button>

        <button
          id="smb-form-toggle-advanced-options"
          mat-button
          type="button"
          ixTest="toggle-advanced-options"
          (click)="this.isAdvancedMode = !this.isAdvancedMode"
        >
          {{ isAdvancedMode ? ('Basic Options' | translate) : ('Advanced Options' | translate) }}
        </button>
      </ix-form-actions>
    </form>
  </mat-card-content>
</mat-card>
